package org.jeecg.modules.screen.service.impl;


import org.jeecg.modules.screen.mapper.ScreenDemoMapper;
import org.jeecg.modules.screen.service.IScreenDemoService;
import org.jeecg.modules.screen.utils.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * @Description: 大屏信息
 * @Author: jeecg-boot
 * @Date: 2020-05-02
 * @Version: V1.0
 */
@Service
public class ScreenDemoServiceImpl implements IScreenDemoService {
    @Autowired
    ScreenDemoMapper screenDemoMapper;

    @Override
    public String queryBgDateState() {
        return screenDemoMapper.queryBgDateState();
    }

    @Override
    public List<Map<String, Object>> queryKeywordTopRank() {
        return screenDemoMapper.queryKeywordTopRank();
    }

    @Override
    public List<Map<String, Object>> querySpiderDis() {
        return screenDemoMapper.querySpiderDis();
    }

    @Override
    public List<Map<String, Object>> querySpiderArticle() {
        return screenDemoMapper.querySpiderArticle();
    }

    @Override
    public Map<String, Object> queryTaskBrief() {

        Map<String, Object> result = screenDemoMapper.getTaskBriefDemo();
        // 获取当前任务数据
//        Integer curTaskCount = screenDemoMapper.getRutaskCount();
//        result.put("current", curTaskCount);
//        // 获取任务历史数据
//        Integer hitaskCount = screenDemoMapper.getHitaskCount();
//        result.put("history", hitaskCount);
//        //过期任务
//        Integer overdue = screenDemoMapper.getOdtaskCount();
//        result.put("overdue", overdue);
//        //总任务
//        result.put("all", curTaskCount + hitaskCount);
//        //待审核
//        Integer waitReview = screenDemoMapper.getWaitReviewCount();
//        result.put("waitReview", waitReview);

        return result;
    }

    @Override
    public Map<String, Object> queryThirdPtFans() {
        List<String> nameList = new ArrayList<>();
        List<Integer> dataList = new ArrayList<>();
        List<Map<String, Object>> basicList = screenDemoMapper.queryThirdPtFans();
        for (int i = 0; i < basicList.size(); i++) {
            nameList.add(basicList.get(i).get("ptName").toString());
            dataList.add(Integer.parseInt(basicList.get(i).get("fansNum").toString()));
        }
        Map<String, Object> retMap = new HashMap<>();
        retMap.put("ptName", nameList);
        retMap.put("fansNum", dataList);
        return retMap;
    }

    @Override
    public List<Map<String, Object>> queryThirdIdAndName() {
        return screenDemoMapper.queryThirdIdAndName();

    }

    @Override
    public Map<String, Object> queryThirdViewAndForward(String id) {
        List<String> dateList = new ArrayList<>();
        List<Integer> viewList = new ArrayList<>();
        List<Integer> forwardList = new ArrayList<>();
        String startDate = DateUtil.getPastDate(30, "yyyyMMdd");
        List<Map<String, Object>> basicList = screenDemoMapper.queryThirdViewAndForward(id, startDate);
        for (int i = 0; i < basicList.size(); i++) {
            dateList.add(basicList.get(i).get("date").toString());
            viewList.add(Integer.parseInt(basicList.get(i).get("viewNum").toString()));
            forwardList.add(Integer.parseInt(basicList.get(i).get("forwardNum").toString()));
        }
        Map<String, Object> retMap = new HashMap<>();
        retMap.put("date", dateList);
        retMap.put("view", viewList);
        retMap.put("forward", forwardList);
        return retMap;
    }

    @Override
    public Integer queryActiveUserTotal() {
        return screenDemoMapper.queryActiveUserTotal();
    }

    @Override
    public Map<String, Object> queryActiveUserEveryDay() {
        List<String> dateList = new ArrayList<>();
        List<Integer> valueList = new ArrayList<>();
        String startTime = DateUtil.getPastDate(7, "yyyy-MM-dd") + " 00:00:00";

        List<Map<String, Object>> basicList = screenDemoMapper.queryActiveUserEveryDay(startTime);
        for (int i = 0; i < basicList.size(); i++) {
            dateList.add(basicList.get(i).get("date").toString());
            valueList.add(Integer.parseInt(basicList.get(i).get("value").toString()));
        }
        Map<String, Object> retMap = new HashMap<>();
        retMap.put("date", dateList);
        retMap.put("value", valueList);
        return retMap;
    }

    @Override
    public Map<String, Object> queryEveryDayViewZX() {
        List<String> dateList = new ArrayList<>();
        List<Integer> valueList = new ArrayList<>();
        String startTime = DateUtil.getPastDate(7, "yyyy-MM-dd") + " 00:00:00";

        List<Map<String, Object>> basicList = screenDemoMapper.queryEveryDayViewZX(startTime);
        for (int i = 0; i < basicList.size(); i++) {
            dateList.add(basicList.get(i).get("date").toString());
            valueList.add(Integer.parseInt(basicList.get(i).get("value").toString()));
        }
        Map<String, Object> retMap = new HashMap<>();
        retMap.put("date", dateList);
        retMap.put("value", valueList);
        return retMap;
    }

    @Override
    public Map<String, Object> queryZXBriefData() {
//        String today = DateUtil.getPastDate(0, "yyyy-MM-dd");
//        String yesterday = DateUtil.getPastDate(1, "yyyy-MM-dd");
//        Map<String, Object> queryMap = new HashMap<>();
//        queryMap.put("today", today);
//        queryMap.put("yesterday", yesterday);
//        Map<String, Object> todayMap = screenDemoMapper.queryZXBriefData(today);
//        Map<String, Object> yesterdayMap = screenDemoMapper.queryZXBriefData(yesterday);
//        queryMap.clear();
//        queryMap.putAll(todayMap);
//        queryMap.put("uv_per",
//                !todayMap.get("uv").toString().equals("0") ? (100 * Integer.parseInt(todayMap.get("uv").toString()) - Integer.parseInt(yesterdayMap.get("uv").toString())) / Integer.parseInt(todayMap.get("uv").toString()) : 0);
//        queryMap.put("pv_per",
//                !todayMap.get("pv").toString().equals("0") ? (100 * Integer.parseInt(todayMap.get("pv").toString()) - Integer.parseInt(yesterdayMap.get("pv").toString())) / Integer.parseInt(todayMap.get("pv").toString()) : 0);
//        queryMap.put("vv_per",
//                !todayMap.get("vv").toString().equals("0") ? (100 * Integer.parseInt(todayMap.get("vv").toString()) - Integer.parseInt(yesterdayMap.get("vv").toString())) / Integer.parseInt(todayMap.get("vv").toString()) : 0);
//        queryMap.put("ip_per",
//                !todayMap.get("ip").toString().equals("0") ? (100 * Integer.parseInt(todayMap.get("ip").toString()) - Integer.parseInt(yesterdayMap.get("ip").toString())) / Integer.parseInt(todayMap.get("ip").toString()) : 0);
        Map<String, Object> queryMap =  screenDemoMapper.queryZXBriefDataDemo();
        return queryMap;
    }

    @Override
    public List<Map<String, Object>> queryHotRemark() {
        return  screenDemoMapper.queryHotRemark();
    }

    @Override
    public List<Map<String, Object>> queryOdTaskList() {
        return  screenDemoMapper.queryOdTaskList();
    }

    @Override
    public List<Map<String, Object>> queryContentDataByType() {
        return  screenDemoMapper.queryContentDataByType();
    }

    @Override
    public List<Map<String, Object>> queryJonList() {
        //查询用户信息
        List<Map<String, Object>> list = screenDemoMapper.queryJonList();
        for(int i = 0 ; i <list.size();i++){
            List<Map<String, Object>> taskInfo = screenDemoMapper.queryOdTaskList();
            if(null != taskInfo && taskInfo.size() > 0){
                list.get(i).put("taskInfo",taskInfo);
            }
        }
        return  list;
    }

    @Override
    public String getSwitch() {
        return  screenDemoMapper.getSwitch();
    }
}
